import os
import time
import itertools

lrs = [2]
regss = [0.002]
inits = [0.66]
dims = [64]

epochs = [100]

model = 'ffm'  # 每次调参，必须固定一种模型
model_file = 'model_ffm_19_two.out'
pre_train = 'no'

runed_id = 1
runing_id = []
max_run_num = 1
running_num = 0

for grid in itertools.product(lrs, regss, dims, inits, epochs):
    lr, regs, dim, init, epoch = grid
    if running_num == max_run_num:
        while True:
            for run_id in runing_id:
                time.sleep(15)
                # logging.info('scanning %d.log......\n',run_id)
                for line in open(str(run_id) + '_' + model + '_submit.log'):
                    if '完成训练' in line:
                        running_num -= 1
                        runing_id.remove(run_id)

            if running_num != max_run_num:
                break

    os.system(' nohup python3.6 -u submit-main.py --dim ' + str(dim) + ' \
    --init ' + str(init) + ' --lr ' + str(lr) + ' \
    --model ' + model + ' --epoch ' + str(epoch) + ' \
    --l2 ' + str(regs) + ' \
    --pre_train ' + pre_train + ' \
    --model_file ' + model_file + ' \
    --run_id ' + str(runed_id) + ' >' + str(runed_id) + '_' + model + '_submit.log 2>&1 &')
    runing_id.append(runed_id)
    runed_id += 1
    running_num += 1
